﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class EvalStudent : System.Web.UI.Page
    {
        private static SqlConnection        gConn;
        private static List<string>         gStudentName;
        private static string               gTeacherEmail;
            
        protected void Page_Load(object sender, EventArgs e)
        {
            Init();
        }

        public void Init()
        {
            gStudentName = new List<string>();
            gTeacherEmail = TeacherScheduleaspx.GetTeacherEmail();

            gConn = new SqlConnection();
            gConn.ConnectionString = "data source=ANDREW-PC\\MYDB;" + "initial catalog=mydb;"
                + "user id=sa;" + "password=rntqkdl1";

            gConn.Open();

            string query = "select student_email from DO_SUBJECT where teacher_email = 'dksxogudsla@naver.com'"; 
                //+ TeacherScheduleaspx.GetTeacherEmail() + "'";
            // 먼저 앞 페이지 실행 후 하는거니까 상관 없다.

            SqlCommand myCom = new SqlCommand(query, gConn);
            SqlDataReader myReader = myCom.ExecuteReader();

            int i = 1;
            while (myReader.Read())
            {
                gStudentName.Add(myReader.GetString(0));
                SetRadoBtnCnt(i, myReader);
                ++i;
            }
            if (i == 1) Button1.Enabled = false;
              
            myReader.Close();

        }

        public void SetRadoBtnCnt(int i, SqlDataReader myReader)
        {
            switch (i)
            {
                case 1:
                    Label1.Visible = true;
                    RadioButtonList1.Visible = true;
                    Label1.Text = myReader.GetString(0);
                    break;
                case 2:
                    Label2.Visible = true;
                    RadioButtonList2.Visible = true;
                    Label2.Text = myReader.GetString(0);
                    break;
                case 3:
                    Label3.Visible = true;
                    RadioButtonList3.Visible = true;
                    Label3.Text = myReader.GetString(0);
                    break;
                case 4:
                    Label4.Visible = true;
                    RadioButtonList4.Visible = true;
                    Label4.Text = myReader.GetString(0);
                    break;
                case 5:
                    Label5.Visible = true;
                    RadioButtonList5.Visible = true;
                    Label5.Text = myReader.GetString(0);
                    break;
            }
        }

        protected void Page_UnLoad(object sender, EventArgs e)
        {
            gConn.Close();
        }
        
        public void ShowMsgBox() 
        {
             Response.Write(@"<script language='javascript'>alert('Ok');</script>"); 
        }

        public static SqlConnection GetSqlConn()
        {
            return gConn;
        }

        public static List<string> GetMyStudentName()
        {
            return gStudentName;
        }
    }
}